import random
# 1. 生成牌
def alex():
    poke_types = ['♥', '♠', '♦', '♣']
    poke_nums = [2, 3, 4, 5, 6, 7, 8, 9, 10, 'J', 'Q', 'K', 'A']
    poke_list = []
    for poke_type in poke_types:
        count = 2
        for poke_num in poke_nums:
            card = [f'{poke_type}{poke_num}', count]
            poke_list.append(card)
            count += 1
    # print(poke_list)
    return poke_list

pokeList = alex()
players = ['默默', '观日落', '志强', 'CX330','小公主','两个', 'Jack','飞猪']
# print(pokeList)
def blackGirl(pl, pk, pn):

    players_dic = {}
    for p_name in pl:
        p_cards = random.sample(pk, pn)

        for card in p_cards:
            pk.remove(card)
        players_dic[p_name] = p_cards
        print(f"为玩家【{p_name}】 生成了牌：{p_cards}")
    return players_dic

playersDic = blackGirl(players,pokeList,3)

def sortList(dataList):
    length = len(dataList)
    for i in range(length):
        for j in range(length-i-1):
            if dataList[j][1] > dataList[j+1][1]:
                dataList[j], dataList[j+1] = dataList[j+1], dataList[j]
    return dataList

def calculate_single(p_cards, score):
    # score = 0
    p_cards = sortList(p_cards)
    weight_val = [0.1, 1, 10]
    count = 0
    for card in p_cards:
        score += card[1] * weight_val[count]
        count += 1
    print(f"计算单牌的结果是：{score}")
    return score

def calculate_pair(p_cards, score):
    p_cards = sortList(p_cards)
    card_val = [i[1] for i in p_cards]

    if len(set(card_val)) == 2:
        if card_val[0] == card_val[1]:
            score = (card_val[0] + card_val[1]) * 50 + card_val[2]
        else:
            score = (card_val[1] + card_val[2]) * 50 + card_val[0]
    print(f"计算对子的结果是：{score}")
    return score

def calculate_straight(p_cards, score):
    p_cards = sortList(p_cards)
    card_val = [i[1] for i in p_cards]
    a, b, c = card_val
    if b - a == 1 and c - b == 1:
        score *= 100
    print(f"计算顺子的结果是：{score}")
    return score
def calculate_same_color(p_cards, score):
    color_val = [i[0][0] for i in p_cards]

    if len(set(color_val)) == 1:
        score *= 1000
    print(f"计算同花的结果是：{score}")
    return score

def calculate_same_color_straight(p_cards, score):
    color_val = [i[0][0] for i in p_cards]

    if len(set(color_val)) == 1:
        p_cards = sortList(p_cards)
        card_val = [i[1] for i in p_cards]
        a, b, c = card_val
        if b - a == 1 and c - b == 1:
            score *= 0.1
        print(f"计算同花顺的结果是：{score}")
    return score

def calculate_leopard(p_cards, score):
    card_val = {i[1] for i in p_cards}
    if len(card_val) == 1:
        # print("ddddddddddddddddddddd")
        score *= 100000
    print(f"计算豹子的的结果是：{score}")
    # print("ddddddddddddddddddddd",p_cards,score)
    return score

calc_func_orders = [
    calculate_single,
    calculate_pair,
    calculate_straight,
    calculate_same_color,
    calculate_same_color_straight,
    calculate_leopard
]
players_score = []
for p_name, p_cards in playersDic.items():
    print(f"开始计算玩家 【{p_name}】的牌了：{p_cards}")
    score = 0
    for calc_func in calc_func_orders:
        score = calc_func(p_cards, score)
    players_score.append([p_name, score])
# print(75.2 * 100000)
winner = sortList(players_score)[-1]
print(f"恭喜最后获胜的玩家是：【{winner[0]}】, 得分是{winner[1]}")
